Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add get organisation user vouch count by source #145

Merged
merged 3 commits into from
Nov 5, 2024

Conversation

MohammadPCh
Copy link
Collaborator

@MohammadPCh MohammadPCh commented Nov 5, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new method to fetch vouch counts by user based on specified criteria, enhancing user-specific data retrieval.
    • Added new data structures for improved handling of vouch count information.
  • Bug Fixes

    • Implemented validation for date inputs to ensure accurate data retrieval.
  • Documentation

    • Updated type imports to reflect new data structures for clarity and consistency.

Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

Walkthrough

The changes introduce a new method getOrganisationUserVouchCountBySource in the OrganisationResolver class, allowing for the retrieval of vouch counts by user based on a specified source and date range. Additionally, two new classes, VouchCountByUser and VouchCountByUserResult, are added to enhance the data structures related to vouch counts. The method includes validations and error handling consistent with existing implementations.

Changes

File Path Change Summary
src/server-extension/organization-resolver.ts - Added method getOrganisationUserVouchCountBySource for fetching vouch counts by user.
- Updated imports to include VouchCountByUser and VouchCountByUserResult.
src/server-extension/types.ts - Introduced new classes VouchCountByUser and VouchCountByUserResult with relevant fields.

Possibly related PRs

Suggested reviewers

  • aminlatifi

🐰 In the code where numbers dance,
A new method takes its chance.
With vouches counted, clear and bright,
Users cheer with pure delight!
From source to date, the data flows,
In the world of code, the rabbit knows! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
src/server-extension/types.ts (2)

42-49: Consider renaming attestorId to be more descriptive.

While the implementation is correct, consider renaming attestorId to something more descriptive like userId or voucherId to better reflect its purpose in the context of vouch counting.


51-58: LGTM! Consider adding JSDoc comments.

The implementation is well-structured and follows the existing patterns. To improve maintainability, consider adding JSDoc comments to describe the purpose of this result type and its fields.

Example documentation:

+/**
+ * Represents the result of counting vouches grouped by user
+ */
 @ObjectType()
 export class VouchCountByUserResult {
+  /** Total number of vouches across all users */
   @Field(() => Int)
   totalVouches: number = 0;

+  /** Breakdown of vouch counts per user */
   @Field(() => [VouchCountByUser])
   vouchCountByUser: VouchCountByUser[] = [];
 }
src/server-extension/organization-resolver.ts (3)

116-135: Consider performance optimizations for the SQL query

A few suggestions to optimize the query:

  1. Consider using LEFT JOIN instead of INNER JOIN if you need to include attestors with no vouches
  2. Add pagination to handle large result sets
  3. Consider adding appropriate indexes for the WHERE clause conditions
-        SELECT 
-          attestor_organisation.attestor_id AS attestor_id,
-          COUNT(*) AS total_count
-        FROM 
-          project_attestation
-        JOIN attestor_organisation 
-          ON project_attestation.attestor_organisation_id = attestor_organisation.id
-        JOIN project
-          ON project_attestation.project_id = project.id
-        WHERE 
-          attestor_organisation.organisation_id = $1
-          AND project.source = $2
-          AND project_attestation.vouch = true
-          AND project_attestation.attest_timestamp BETWEEN $3 AND $4
-        GROUP BY 
-          attestor_organisation.attestor_id
-        ORDER BY 
-          total_count DESC;
+        SELECT 
+          attestor_organisation.attestor_id AS attestor_id,
+          COUNT(*) AS total_count
+        FROM 
+          project_attestation
+        LEFT JOIN attestor_organisation 
+          ON project_attestation.attestor_organisation_id = attestor_organisation.id
+        LEFT JOIN project
+          ON project_attestation.project_id = project.id
+        WHERE 
+          attestor_organisation.organisation_id = $1
+          AND project.source = $2
+          AND project_attestation.vouch = true
+          AND project_attestation.attest_timestamp BETWEEN $3 AND $4
+        GROUP BY 
+          attestor_organisation.attestor_id
+        ORDER BY 
+          total_count DESC
+        LIMIT $5
+        OFFSET $6;

156-161: Enhance error handling with specific error types

The current error handling catches all errors and wraps them in a generic Error. Consider:

  1. Creating specific error types for different failure scenarios
  2. Adding more context in error messages (e.g., including the organisationId)
-    } catch (error: any) {
-      console.error("Error fetching attestor vouch count by source:", error);
-      throw new Error(
-        `Failed to fetch attestor vouch count by source: ${error.message}`
-      );
+    } catch (error: any) {
+      console.error(
+        `Error fetching attestor vouch count by source for organisation ${organisationId}:`,
+        error
+      );
+      if (error.code === '23503') {  // Foreign key violation
+        throw new Error(`Organisation ${organisationId} not found`);
+      }
+      throw new Error(
+        `Failed to fetch attestor vouch count by source for organisation ${organisationId}: ${error.message}`
+      );

93-162: Consider adding unit tests for the new functionality

The new query method should be thoroughly tested, including:

  • Happy path with various date ranges
  • Edge cases for date validation
  • Error scenarios
  • Empty result handling

Would you like me to help generate comprehensive unit tests for this new functionality?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 034c348 and a3858c1.

📒 Files selected for processing (2)
  • src/server-extension/organization-resolver.ts (2 hunks)
  • src/server-extension/types.ts (1 hunks)
🔇 Additional comments (2)
src/server-extension/types.ts (1)

41-58: Verify consistent naming across the codebase.

Let's verify that the naming conventions used in these new types are consistent with the rest of the codebase.

✅ Verification successful

Based on the search results, I can now generate the final response:

Naming conventions are consistent across the codebase

The naming conventions used in these new types are consistent with the existing codebase patterns:

  • The term "attestor" is consistently used throughout (not "attester")
  • The suffix "Result" for response types follows the established pattern
  • The camelCase naming for properties is consistent
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check naming conventions for similar types and fields

# Check for other uses of "attestor" vs "user" terminology
rg -i "attestor|vouch.*user" --type ts

# Check for similar result type patterns
ast-grep --pattern '@ObjectType()
export class $_Result {
  $$$
}'

Length of output: 10727

src/server-extension/organization-resolver.ts (1)

3-8: LGTM: Import changes are appropriate

The new type imports align with the added functionality and follow the existing import pattern.

src/server-extension/organization-resolver.ts Show resolved Hide resolved
@MohammadPCh MohammadPCh merged commit 585ef9c into develop Nov 5, 2024
@MohammadPCh MohammadPCh deleted the feat/add-getOrganisationUserVouchCountBySource branch November 5, 2024 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant